package com.meituan.catering.management.order.biz.model.converter;

import com.meituan.catering.management.order.api.http.model.enumeration.CateringOrderItemAccessoryStatusEnum;
import com.meituan.catering.management.order.api.http.model.enumeration.CateringOrderItemStatusEnum;
import com.meituan.catering.management.order.api.http.model.enumeration.CateringOrderPaymentChannelEnum;
import com.meituan.catering.management.order.api.http.model.enumeration.CateringOrderStatusEnum;
import com.meituan.catering.management.order.biz.model.CateringOrderBO;
import com.meituan.catering.management.order.biz.model.CateringOrderItemAccessoryBO;
import com.meituan.catering.management.order.biz.model.CateringOrderItemBO;
import com.meituan.catering.management.order.dao.model.CateringOrderDO;
import com.meituan.catering.management.order.dao.model.CateringOrderItemAccessoryDO;
import com.meituan.catering.management.order.dao.model.CateringOrderItemDO;

/**
 * 从其他数据模型向订单BO的转换器
 */
public abstract class CateringOrderBOConverter {

    /**
     * 根据DO转换为BO
     *
     * @return BO
     */
    public static CateringOrderBO fromDO(CateringOrderDO cateringOrderDO) {
        CateringOrderBO cateringOrderBO = new CateringOrderBO();
        cateringOrderBO.setId(cateringOrderDO.getId());
        cateringOrderBO.setStatus(CateringOrderStatusEnum.valueOf(cateringOrderDO.getStatus()));
        cateringOrderBO.setComment(cateringOrderDO.getComment());
        /*
         * 前端传入的字符串人数
         */
        cateringOrderBO.setCustomerCount(Integer.valueOf(cateringOrderDO.getCustomerCount()));
        cateringOrderBO.setTableNo(cateringOrderDO.getTableNo());
        cateringOrderBO.setTotalPrice(cateringOrderDO.getTotalPrice());
        cateringOrderBO.setVersion(cateringOrderDO.getVersion());
        cateringOrderBO.setTenantId(cateringOrderDO.getTenantId());
        /*
         * 审计
         */
        cateringOrderBO.getAuditing().setCreatedAt(cateringOrderDO.getCreatedAt());
        cateringOrderBO.getAuditing().setCreatedBy(cateringOrderDO.getCreatedBy());
        cateringOrderBO.getAuditing().setLastModifiedAt(cateringOrderDO.getLastModifiedAt());
        cateringOrderBO.getAuditing().setLastModifiedBy(cateringOrderDO.getLastModifiedBy());
        /*
         * 门店
         */
        cateringOrderBO.setShopBusinessNo(cateringOrderDO.getShopBusinessNo());
        cateringOrderBO.setShopId(cateringOrderDO.getShopId());
        cateringOrderBO.setShopName(cateringOrderDO.getShopNameOnPlace());
        cateringOrderBO.setBillingPaid(cateringOrderDO.getBillingPaid());
        if (cateringOrderDO.getBillingPaymentChannel() != null) {
            cateringOrderBO.setBillingPaymentChannel(CateringOrderPaymentChannelEnum.valueOf(cateringOrderDO.getBillingPaymentChannel()));
        }
        cateringOrderBO.setBillingPromotion(cateringOrderDO.getBillingPromotion());
        return cateringOrderBO;
    }

    /**
     * AccessoryDO 转BO
     */
    public static CateringOrderItemAccessoryBO fromItemAccessoryDO(CateringOrderItemAccessoryDO accessoryDO) {
        CateringOrderItemAccessoryBO accessoryBO = new CateringOrderItemAccessoryBO();
        accessoryBO.setId(accessoryDO.getId());
        accessoryBO.setStatus(CateringOrderItemAccessoryStatusEnum.valueOf(accessoryDO.getStatus()));
        accessoryBO.setSeqNo(accessoryDO.getSeqNo());
        accessoryBO.setVersion(accessoryDO.getVersion());
        /*
         * 商品快照转换
         */
        accessoryBO.getProductAccessorySnapshotOnPlace().setName(accessoryDO.getProductAccessoryNameOnPlace());
        accessoryBO.getProductAccessorySnapshotOnPlace().setGroupName(accessoryDO.getProductAccessoryGroupNameOnPlace());
        accessoryBO.getProductAccessorySnapshotOnPlace().setId(accessoryDO.getProductAccessoryId());
        accessoryBO.getProductAccessorySnapshotOnPlace().setUnitPrice(accessoryDO.getProductAccessoryUnitPriceOnPlace());
        accessoryBO.getProductAccessorySnapshotOnPlace().setUnitOfMeasure(accessoryDO.getProductAccessoryUnitOfMeasureOnPlace());
        /*
         * 数量快照转换
         */
        accessoryBO.getQuantity().setOnPlace(accessoryDO.getPlaceQuantity());
        accessoryBO.getQuantity().setOnProduce(accessoryDO.getProduceQuantity());
        accessoryBO.getQuantity().setLatest(accessoryDO.getLatestQuantity());
        return accessoryBO;

    }

    /**
     * CateringOrderItemDO 转BO
     */
    public static CateringOrderItemBO fromOrederItemDO(CateringOrderItemDO cateringOrderItemDO) {
        CateringOrderItemBO cateringOrderItemBO = new CateringOrderItemBO();
        cateringOrderItemBO.setId(cateringOrderItemDO.getId());
        cateringOrderItemBO.setStatus(CateringOrderItemStatusEnum.valueOf(cateringOrderItemDO.getStatus()));
        cateringOrderItemBO.setVersion(cateringOrderItemDO.getVersion());
        cateringOrderItemBO.setSeqNo(cateringOrderItemDO.getSeqNo());
        /*
         * 子项做法
         */
        cateringOrderItemBO.getProductMethodSnapshotOnPlace().setGroupName(cateringOrderItemDO.getProductMethodGroupNameOnPlace());
        cateringOrderItemBO.getProductMethodSnapshotOnPlace().setId(cateringOrderItemDO.getProductMethodId());
        cateringOrderItemBO.getProductMethodSnapshotOnPlace().setName(cateringOrderItemDO.getProductMethodNameOnPlace());
        /*
         * 子项数量
         */
        cateringOrderItemBO.getQuantity().setOnPlace(cateringOrderItemDO.getPlaceQuantity());
        cateringOrderItemBO.getQuantity().setOnProduce(cateringOrderItemDO.getProduceQuantity());
        cateringOrderItemBO.getQuantity().setLatest(cateringOrderItemDO.getLatestQuantity());
        /*
         * 子项商品
         */
        cateringOrderItemBO.getProductSnapshotOnPlace().setId(cateringOrderItemDO.getProductId());
        cateringOrderItemBO.getProductSnapshotOnPlace().setName(cateringOrderItemDO.getProductNameOnPlace());
        cateringOrderItemBO.getProductSnapshotOnPlace().setUnitPrice(cateringOrderItemDO.getProductUnitPriceOnPlace());
        cateringOrderItemBO.getProductSnapshotOnPlace().setUnitOfMeasure(cateringOrderItemDO.getProductUnitOfMeasureOnPlace());
        return cateringOrderItemBO;
    }


}
